package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.entity.Result;
import cn.itcast.service.ReportOrderService;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportOrderController {

    @Reference(version = "1.0.0")
    private ReportOrderService reportOrderService;

    /**
     * 预约支付统计
     * @return
     */
    @GetMapping("/order")
    public Result reportOrder(){
        List<String> months=new ArrayList<>();
        //获取当前日期
        Calendar calendar = Calendar.getInstance();
        //根据当前日期获取去年的日期
        calendar.add(Calendar.YEAR,-1);
        //格式化时间仅需要年月
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
        for (int i = 0; i < 12; i++) {
            //获取去年到现在的每一个月份 月份每次+1
            calendar.add(Calendar.MONTH,1);
            months.add(sdf.format(calendar.getTime()));
        }

        Map<String, Object> map = this.reportOrderService.queryPayAndOrderCountByDate(months);
        return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS,map);


    }

}
